package cn.livingCloud.service.impl.operation;

import cn.livingCloud.context.BeanProvider;
import cn.livingCloud.context.Config;
import cn.livingCloud.dto.MemberListDto;
import cn.livingCloud.dto.front.SelfBindingFrontFormDto;
import cn.livingCloud.entity.core.SelfBinding;
import cn.livingCloud.entity.user.Member;
import cn.livingCloud.repository.MemberMapper;
import cn.livingCloud.repository.SelfBindingMapper;
import cn.livingCloud.utils.SessionUtils;

import java.util.List;

/**
 * Created by DingJie on 2016/6/24.
 */
public class SelfBindingFrontFromDtoLoader {
    private transient SelfBindingMapper selfBindingMapper = BeanProvider.getBean(SelfBindingMapper.class);
    private transient MemberMapper memberMapper = BeanProvider.getBean(MemberMapper.class);
    private SelfBindingFrontFormDto formDto;

    public SelfBindingFrontFromDtoLoader(SelfBindingFrontFormDto formDto) {
        this.formDto = formDto;
    }

    public void loader() {
        //获取当前粉丝(创建人)
        Member member = testMember();
        SelfBinding selfBinding = new SelfBinding();
        selfBinding.setPhone(formDto.getPhone());
        selfBinding.setEmployeeName(formDto.getEmployeeName());
        selfBinding.setDeptName(formDto.getDeptName());
        selfBinding.setMemberUuid(member.getUuid());
        selfBindingMapper.insert(selfBinding);
    }

    @Deprecated
    private Member testMember() {
        //如果是测试模式就拿member表中的第一条数据
        if (Config.ENVIRONMENT.equals("development")) {
            MemberListDto listDto = new MemberListDto();
            List<Member> list = memberMapper.getList(listDto);
            return list.get(0);
        }
        return (Member) SessionUtils.getCurrentMember();
    }
}
